<?php /*a:2:{s:71:"/www/wwwroot/cloud_boss/application/admin/view/equipment/mainboard.html";i:1604050254;s:64:"/www/wwwroot/cloud_boss/application/admin/view/public/basic.html";i:1573743224;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><?php echo htmlentities((isset($title) && ($title !== '')?$title:'重庆优合一众')); ?></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugs/layui/css/layui.css" media="all"/>
    <!--<link rel="stylesheet" href="/static/layuicms/css/index.css" media="all" />-->
    
<link rel="stylesheet" href="/static/css/admin/public.css" media="all"/>

</head>
<body class="<?php echo htmlentities((isset($body) && ($body !== '')?$body:'childrenBody')); ?>">

<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <input type="hidden" id="app_sn" value="<?php echo htmlentities($app_sn); ?>"/>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input model" placeholder="请输入主板型号"/>
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>

            <?php if(auth("$thisClass/add_mainboard")): ?>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-sm addNews_btn">新增</a>
            </div>
            <?php endif; ?>

        </form>
    </blockquote>
    <table id="userList" lay-filter="userList"></table>
    <script type="text/html" id="checkStatus">
        <input type="checkbox" name="{{d.mainboard_id}}" value="{{d.status}}" lay-skin="switch" lay-text="启用|冻结"
               lay-filter="modifyStatus" {{ d.status== 1 ? 'checked' : '' }}>
    </script>

    <!--操作-->
    <script type="text/html" id="userListBar">

        <!--<?php if(auth("$thisClass/edit_password")): ?>-->
        <!--<a class="layui-btn layui-btn-sm layui-btn-green" lay-event="edit_password">修改密码</a>-->
        <!--<?php endif; ?>-->

        <?php if(auth("$thisClass/edit")): ?>
        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
        <?php endif; if(auth("$thisClass/del")): ?>
        <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
        <?php endif; ?>

        <!-- <a class="layui-btn layui-btn-sm layui-btn-warm" onclick="getSetting('{{d.company_id}}')">设置服务费</a>-->
    </script>

</form>

<script type="text/javascript" src="/static/plugs/jquery/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="/static/plugs/layui/layui.js"></script>
<script type="text/javascript" src="/static/admin.js"></script>
<script type="text/javascript" src="/static/js/admin/api.js"></script>

<script>
    layui.use(['laydate', 'form', 'layer', 'table', 'laytpl','upload'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            upload = layui.upload,
            table = layui.table,
            laydate = layui.laydate;

        //日期范围
        laydate.render({
            elem: '#create_at'
            , range: true
        });
        var api_host = "<?php echo htmlentities($api_host); ?>";
        //主板型号列表


        var tableIns = table.render({
            elem: '#userList',
            url: api_host + 'Boss/Mainboard/getLists',
            method: 'POST',
            contentType: 'application/json; charset=UTF-8',
            headers: {
                "token": 'bbbbb'
            },
            cellMinWidth: 95,
            page: true,
            where: {app_sn: $("#app_sn").val()},
            height: "full-125",
            limits: [10, 15, 20, 25],
            limit: 20,
            id: "userListTable",
            request: {
                limitName: 'pageSize', //每页数据量的参数名，默认：limit
            },
            cols: [[
                {field: 'model', title: '主板型号', minWidth: 200, align: "center"},
                {field: 'edition', title: '版本', minWidth: 200, align: 'center'},
                {field: 'source', title: '来源', minWidth: 200, align: 'center'},
                {
                    field: 'status_name',
                    title: '启用状态',
                    minWidth: 100,
                    templet: '#checkStatus',
                    unresize: true,
                    align: "center"
                },
                {field: 'create_time', title: '添加时间', minWidth: 200, align: 'center'},
                {title: '操作', minWidth: 175, templet: '#userListBar', fixed: "right", align: "center"}
            ]]
        });

        //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
        $(".search_btn").on("click", function () {

            if ($(".searchVal").val() != '') {
                //执行重载
                table.reload('userListTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        //传参数
                        model: $(".model").val(),
                        app_sn: $("#app_sn").val(),

                    },

                });
                table.render();
                // layer.msg('查询成功');
            } else {
                layer.msg("请输入搜索的内容");
            }
        });

        //监听状态操作
        form.on('switch(modifyStatus)', function (obj) {
            var api_host = "<?php echo htmlentities($api_host); ?>";
            $.ajax({
                method: "POST",
                url: api_host + 'Boss/Mainboard/changeStatus',
                contentType: 'application/json; charset=UTF-8',
                header: {
                    'token': "bbbb", // 默认值
                },
                dataType: 'json',
                data: JSON.stringify({mainboard_id: this.name}),
                success: (data) => {
                    if (data.code == 1) {
                        layer.msg(data.msg, {icon: 1});
                    } else {
                        layer.msg(data.msg, {icon: 2}, function () {
                            tableIns.reload();
                            layer.close();
                        });
                    }
                },
                error: () => {
                    layer.msg('系统错误，请稍后再试', {icon: 2}, function () {
                        tableIns.reload();
                    });
                }
            })
        });

        //列表操作
        table.on('tool(userList)', function (obj) {

            var layEvent = obj.event,
                data = obj.data;
            var element = layui.element;
            var $ = layui.jquery,
                upload = layui.upload;

            if (layEvent === 'edit') { //编辑
                editUser(data);
            } else if (layEvent === 'del') { //删除
                var api_host = "<?php echo htmlentities($api_host); ?>";
                layer.confirm('确定删除此主板？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post(api_host + 'Boss/Mainboard/del', {mainboard_id: data.mainboard_id}, function (res) {
                        if (res.code == 1) {
                            layer.msg(res.msg, {icon: 1}, function () {
                                tableIns.reload();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, "json")

                });
            } else if (layEvent === 'import') { //导入
                var id = $(this).attr('data-id');
                var api_hosts = "<?php echo htmlentities($api_host); ?>";
                upload.render({
                    elem: this,
                    //url: api_hosts + 'Boss/Equipment/imports',
                    url: '../../json/userface.json',
                    data: {id: id},
                    //accept: 'file', //普通文件,
                    auto:true,//是否自动上传
                    method : "post",  //此处是为了演示之用，实际使用中请将此删除，默认用post方式提交
                    done: function(res, index, upload){
                        console.log('res');
                        console.log(2222222);
                        var num = parseInt(4*Math.random());  //生成0-4的随机数，随机显示一个头像信息
                        $('.linkLogoImg').attr('src',res.data[num].src);
                        $('.linkLogo').css("background","#fff");
                    }
                });
            }
        });

    });

    $(".addNews_btn").click(function () {
        addUser();
    });


    // 添加
    function addUser(edit) {
        var index = layui.layer.open({
            title: "新增主板型号",
            type: 2,
            content: '<?php echo url("$thisClass/add_mainboard"); ?>?app_sn='+$("#app_sn").val(),
            success: function (layero, index) {

                setTimeout(function () {
                    layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        });
        layui.layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layui.layer.full(index);
        })
    }
    //导入
    $(".import_btn").click(function () {
        var index = layui.layer.open({
            title: "导入",
            type: 2,
            content: '<?php echo url("$thisClass/import"); ?>?app_sn='+$("#app_sn").val(),
            success: function (layero, index) {

                setTimeout(function () {
                    layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        });
        layui.layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layui.layer.full(index);
        })
    });


    //编辑
    function editUser(edit) {
        var index = layui.layer.open({
            title: "编辑主板",
            type: 2,
            content: '<?php echo url("$thisClass/edit_mainboard"); ?>?mainboard_id=' + edit.mainboard_id+"&app_sn="+$("#app_sn").val(),
            success: function (layero, index) {
                var body = layui.layer.getChildFrame('body', index);
                setTimeout(function () {
                    layui.layer.tips('点击此处返回菜单列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        });
        layui.layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layui.layer.full(index);
        })
    }



    // 下载主板导入模板
    function downloadDevice(){
        window.location.href = "<?php echo config('api.qi_niu_url'); ?>" + 'excel_template.xlsx';
    }



</script>

</body>
</html>